package com.ysd.Dao.Impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Product;
import com.ysd.util.DBmanager;

public class MoHuDaoImpl {

	//产品详情实现类
		public List<Product> getMoHuList(String mohu){//通过模糊查询获取产品详细数据
			List<Product> list = new ArrayList<Product>();
			//1建立连接
			Connection conn = DBmanager.getConnection();
			Statement st = null;
			ResultSet rs = null;
			
			try {//,try正常执行
				//2,创建statement执行对象
				st = conn.createStatement();
				//3,SQL语句
				String sql = "select * from product where productName like '%"+mohu+"%' ";
				rs = st.executeQuery(sql);
				while(rs.next()) {
				    Integer	productId = rs.getInt("productId");
					String productName = rs.getString("productName");
					Integer productPrice = rs.getInt("productPrice");
					Integer salePrice= rs.getInt("salePrice");
					String productTexture = rs.getString("productTexture");
					Integer productCategoryId= rs.getInt("productCategoryId");
					String productPicture= rs.getString("productPicture");
					String productMaterial = rs.getString("productMaterial");
					String productBrand = rs.getString("productBrand");
					String productSize = rs.getString("productSize");
					String productNetDegree = rs.getString("productNetDegree");
					String productColor = rs.getString("productColor");
					String isCutomize = rs.getString("isCutomize");
					String productSpecification = rs.getString("productSpecification");
					Product product=new Product(productId, productName, productPrice, salePrice, productTexture, productCategoryId, productPicture, productMaterial, productBrand, productSize, productNetDegree, productColor, isCutomize, productSpecification);
					list.add(product);
				}
				return list;
			} catch (SQLException e) {//catch异常执行
				e.printStackTrace();
				return null;//异常情况下返回空
			} finally {
				DBmanager.closeAll(conn, st, rs);
			}
		}
}
